#define _CRT_SECURE_NO_WARNINGS 1
#include"linkqueue.h"
void initqueue(queue* q)
{
	node* head = (node*)malloc(sizeof(node));
	assert(head);
	head->data = 0;
	q->front = head;
	q->last = head;
	head->next = NULL;
}
node* newnode()
{
	node* newnode = (node*)malloc(sizeof(node));
	assert(newnode);
	return newnode;
}
void pushback(queue* q, l x)
{
	assert(q);
	node* node = newnode();
	node->data = x;
	node->next = NULL;
	if (q->front->next == NULL)
	{
		q->last = node;
		q->front->next = node;
	}
	else
	{
		q->last->next = node;
		q->last = node;
	}
}
void popfront(queue* q)
{
	assert(q);
	node* cur = q->front->next;
	q->front->next = cur->next;
	free(cur);
	cur = NULL;
	assert(q->front->next);
}
l find(const queue* const q, l location)
{
	assert(q);
	assert(q->front->next);
	node* cur = q->front->next;
	l count = 0;
	while (cur != NULL)
	{
		count++;
		if (count == location)
		{
			return cur->data;
		}
		cur = cur->next;
	}
}
void printqueue(queue q)
{
	node* cur = q.front->next;
	while (cur != NULL)
	{
		printf("%d->", cur->data);
		cur = cur->next;
	}
}